{% extends "../layout/indexLayout.htm"%}
{% block head %}
<script type="text/javascript"><!--
function init(){
    document.getElementById("msg_header").className='active';
  
    var main = new MainPanel({
	     region:'center',
	     html:'<div id="center" ></div>'
	});
	var tb = Ext.create('Ext.toolbar.Toolbar');
    tb.suspendLayout = true;
    tb.render('center');
    tb.add({
        icon: 'list-items.gif', // icons can also be specified inline
        text:'消息列表',
        cls: 'x-btn-icon',
        tooltip: '查看消息列表',
        handler: function(){
           window.location.href="/msg";
        }
    }, '-');

	var name='{{name}}';
	if(name=='yuyu'){
		name='woyo';
	}else{
		name='yuyu';
	}
    var addMsg = Ext.create('Ext.form.Panel', {
        url:'/addMsg',
        method:'post',
        frame:true,
        id:'form',
        name:'form',
        title: '消息信息',
        bodyStyle:'padding:5px 5px 0',
        autoWidth: true,
        fieldDefaults: {
            msgTarget: 'side',
            labelWidth: 75
        },
        defaultType: 'textfield',
        defaults: {
            anchor: '100%'
        },

        items: [{
            fieldLabel: '标题',
            name: 'title',
            allowBlank:false
        },{
            fieldLabel: '内容',
            name: 'content'
        },{
            fieldLabel: '接收者',
            name: 'toUser',
            value:name
        }],

        onSubmit: Ext.emptyFn,
        /*submit: function() 
        {
            this.getEl().dom.action= '/addMsg'; //连接到服务器的url地址
            this.getEl().dom.method='POST',
            this.getEl().dom.submit();
        },*/
        buttons: [{
            text: '发送',
            handler : function() {
	        	/*addMsg.getForm().submit({
	                url: '/addMsg',
	                method:'post',
	                submitEmptyText: false,
	                waitMsg: '发送中...'
	            });*/
	            //addMsg.form.submit();

	            addMsg.getForm().submit({
	            	url:"/addMsg",
	            	method:'post',
	            	params:{},
	            	success: function (c,v,e) { //e: 触发事件
	            		var json=Ext.decode(v.response.responseText);
	            		alert("发送成功");
	            		addMsg.form.reset();
	            	},
	            	failure:function(c,v,e){
	            		alert("发送失败");
	            		addMsg.form.reset();
			        }
	            }) 
            	
 		       	//document.getElementById('form').submit();
			}
        },{
            text: '返回',
            handler : function() {
				window.location.href='/msg';
			}
        }]
    });
    addMsg.render('center');
	
}
--></script>
{% endblock %}

{% block body %}

{% endblock %}